
type datatype=
	 Question
	|QuestionSet
	|Image
    |Jump

type form= Multiple | Single | Drop


type expr=					
	|Atype of string*form* (string list)
	|Title of string*string
	|Text of string* string
    |Link of string*string
    |Jup of string*string
	(*|Display of expr*)
	|Addquestion of string*(string list)
    |Display of string list
    |Call of string * (string list)


type stmt=
	Block of stmt list
	|Expr of expr
	(*|If of expr*stmt*stmt*)

type func_decl={
	fname:string;
	formals:(datatype*string) list;
	locals:(datatype*(string list)) list;
	body:stmt list;
	
}

type program= ( (datatype* (string list)) list )* (func_decl list)

let rec string_of_expr = function
    
    |Atype(e1, e2, e3)-> "the question name is " ^ e1 ^(match e2 with Multiple -> "multiple" 
                                                                    | Single -> "single" 
                                                                    | Drop -> "drop") ^ "answers"
    |Title(e1, e2) -> "the type is" ^ e1 ^ "and contents is" ^ e2
    |Text (e1, e2) -> "the question name is " ^ e1 ^ "and length is" ^ e2
    |Link (e1, e2) -> "the image's name is "^ e1 ^ "  and its value is " ^ e2
    |Jup(e1, e2) -> "the jumpbutton's name is " ^ e1 ^"  and its value is " ^ e2
    |Addquestion (e1, e2)->"the questionsetname is " ^ e1 ^ "and the contents is"
    |Display(e1)->"Display something" 
    |Call(e1, e2)->"call function" ^ e1

let rec string_of_stmt=function
    Block(stmts)->
        "{\n" ^ String.concat "" (List.map string_of_stmt stmts) ^ "}\n"
        |Expr(expr) -> string_of_expr expr ^ ";\n"

let string_of_vdecl sam = ( match (fst(sam)) with Question -> "Question" 
                                            | QuestionSet -> "QuestionSet"
                                            |Jump -> "Jumpbutton" 
                                            |Image -> "image")
                             ^ String.concat "" (snd(sam)) ^ ";\n"
                             

let string_of_formals fs= (match fst(fs) with Question -> "Question" 
                                            | QuestionSet -> "Questionset" 
                                            | Image-> "image"
                                            | Jump -> "Jumpbutton")
                         ^ snd(fs) ^";\n" 

let string_of_fdecl fdecl =
  fdecl.fname ^ "(" ^ String.concat ", " (List.map string_of_formals fdecl.formals) ^ ")\n{\n" ^
  String.concat "" (List.map string_of_vdecl fdecl.locals) ^
  String.concat "" (List.map string_of_stmt fdecl.body) ^
  "}\n"

let string_of_program (vars, funcs) =
  String.concat "" (List.map string_of_vdecl vars) ^ "\n" ^
  String.concat "\n" (List.map string_of_fdecl funcs)
